//功能权限管理
var id;
$(function(){
	var nickName = ly.getUrlParam("nickName");
	id= ly.getUrlParam("id");
	$("#nickName").html(nickName);
	$("#id").val(id);
	//权限分配回显
	var url = site.apiUrl+"/menu/selectBackUserThisMenuByUserId";
	request({
        url: url,
        data:{
        	'backUserId':id,
    	},
        type: 'POST',
        ajaxform:true,
        callback: function(r) {
			console.log(r)
			if(r.code=="rest.success"){
				$("#funList").permissionList({
					"echodataMenu":r.result.menu,
				});
        	}else{
				ly.toast(r.result);
        	}
        }
	});
	
	$("body").on("click","#save-btn",function(){
		var data = $('#funList').permissionList.returndata();
		var fun = data.fun;
		var menu = data.menu;
		if(menu.length >0){
			var m ="";
			var f="";
			for(i = 0;i<menu.length;i++){
				m+=menu[i]+",";
			}
			for(i = 0;i<fun.length;i++){
				f+=fun[i]+",";
			}	
			var obj = {
				'backUserId':id,
				'menuIds':m
			};
			var url = site.apiUrl+"/menu/updateBackUserThisMenu";
			request({
		        url: url,
		        data:obj,
		        type: 'POST',
		        ajaxform:true,
		        callback: function(r) {
					if(r.code=="rest.success"){
						ly.toast("分配成功");
						//延迟1秒后跳转
						setTimeout(function () {
							ly.goto("../backUser.html");
						},1000);
		        	}else{
						ly.toast(data.result);
		        	}
		        }
			});
		}else{
			ly.toast("权限不能为空");
		}
	});
});





